package org.fund.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.fund.common.core.domain.BaseResult;
import org.fund.common.core.model.LoginBody;
import org.fund.common.model.LoginUser;
import org.fund.common.util.SecurityUtils;
import org.fund.framework.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:
 * @Date: 2022/3/8 14:17
 * @Description:
 */
@RestController
@Api(tags = "登录")
public class LoginController {
    @Autowired
    private SysLoginService loginService;


    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public BaseResult login(@RequestBody LoginBody loginBody) {
        // 生成令牌
        String token = loginService.login(loginBody.getUserName(), loginBody.getPassword());
        return BaseResult.success(token);
    }
    @ApiOperation(value = "获取用户信息")
    @GetMapping("/getInfo")
    public BaseResult getInfo(){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return BaseResult.success(loginUser);
    }

}
